package com.iman.sumer.service.impl.teamgroup;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.common.hibernate.TemplateQLService;
import com.iman.common.support.Page;
import com.iman.sumer.service.teamgroup.TeamGroupService;
import com.iman.sumer.vo.teamgroup.TeamGroupVo;

@Service
public class TeamGroupServiceImpl implements TeamGroupService {
	@Inject
    private TemplateQLService templateQLService;

	@Override
	public Page<TeamGroupVo> getGroupList(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<TeamGroupVo> getHotGroupList(Map<String, Object> params) {
		// TODO Auto-generated method stub
		Integer ps = Integer.valueOf(params.get("ps").toString());
		Integer pn = Integer.valueOf(params.get("pn").toString());
		params.put("startNo", ps*pn);
 		Page<TeamGroupVo> vos = templateQLService.findByPagedSQLBeanQuery(
				"hot_group_list", params, Page.getStartOfPage(pn, ps), ps,
				TeamGroupVo.class);
		return vos;
	}

	@Override
	public List<Map> getGroupByID(long teamGroupId) {
		// TODO Auto-generated method stub
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("group_id",teamGroupId);
		List<Map> map = this.templateQLService.findBySQLMapQuery("get_group_by_id", params);
		return map;
	}

	@Override
	public int updateGroup(TeamGroupVo tgv) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	/**
	 * 保存公告
	 * @param params
	 * @return
	 */
	@Override
	public void updateNotice(Map<String, Object> params){
		this.templateQLService.executeSQLUpdate("edit_group_notice", params);
		
	}
	
	/**
	 * 申请或者邀请成员
	 * @param params
	 */
	@Override
	public void addGroupMember(Map params) {
		templateQLService.executeSQLUpdate("hot_group_add_user", params);
	}

	@Override
	public void updateGroupImg(Map params) {
		templateQLService.executeSQLUpdate("update_gourp_img", params);
	}

	/**
	 * 个人群组管理
	 * 
	 */
	@Override
	public List<TeamGroupVo> selfGroupManage(Map<String, Object> params) {
		List<TeamGroupVo> vos = new Vector<TeamGroupVo>();
		List<TeamGroupVo> list1 = templateQLService.findBySQLBeanQuery("find_creater_group", params, TeamGroupVo.class);
		vos.addAll(list1);
		List<TeamGroupVo> list2 = templateQLService.findBySQLBeanQuery(
				"self_group_manage", params, TeamGroupVo.class);
		vos.addAll(list2);
		return vos;
	}

	@Override
	public void addGroup(Map params) {
//		templateQLService.executeSQLUpdate("add_group_base", params)
		templateQLService.executeSQLUpdate("add_group_base", params);
		templateQLService.executeSQLUpdate("add_group_manage", params);
		templateQLService.executeSQLUpdate("add_group_ext", params);
	}

	@Override
	public void exitGroup(Map params) {
		templateQLService.executeSQLUpdate("exit_group", params);
	}

	@Override
	public List<Map> getGroupType() {
		Map<String,Object> params = new HashMap<String,Object>();
		List<Map> res = templateQLService.findBySQLMapQuery("group_type", params);
		return res;
	}

}
